import React, { Component } from 'react';
import Task from '../component/Task'
import { WholeStyled } from './WholeStyled'

import qs from "qs";
import { Toast } from 'antd-mobile'
import { userData } from 'pages/dengluzhuce/model/userData.js'
import mrtx from 'images/my/denglutouxiang.png'
import connect from 'pages/redux-component/connect'

class HighTask extends Component {
  state = {
    taskList : [],

  }
  componentDidMount(){
    console.log(userData.uid)
    let body = {uid: userData.uid}
    console.log(body)
    fetch('/Legang/task/findAllPrice',{   
      method:"POST",
      headers:{
          "Content-type":"application/x-www-form-urlencoded",
      },     
      body: qs.stringify(body)
    })    
    .then(response => response.json())
    .then(result => {
      if(result.flag){
        console.log(result)
        this.setState({
          taskList : result.data
        },
        ()=>{
          console.log(this.state.taskList)
          }
        )
      }else{
        Toast.info(result.errorMsg)
      }
      
    })
  }
  render() {
    return (
      <WholeStyled>
        {
          this.state.taskList.map((value,index)=>{
            value.hdimg = 'http://laienli.cn:8080/Legang/'+value.himg
            if(value.himg){
              console.log(value.himg)
              let _arr = value.himg.split("Legang\\")
              if(_arr.length>1)
                value.hdimg = 'http://laienli.cn:8080/Legang/'+_arr[1]
            }else{
              value.hdimg = mrtx
              console.log(value.hdimg)
            }
            if(value.exp){
              if(value.exp>=500){
                value.jd = '100%'
                value.dj = 'lv5'
              }else if(value.exp>=400){
              value.jd = '80%'
              value.dj = 'lv4'
              }else if(value.exp>=300){
              value.jd = '60%'
              value.dj = 'lv3'
              }else if(value.exp>=200){
              value.jd = '40%'
              value.dj = 'lv2'
              }else{
                value.dj = 'lv1'  
                value.jd = '20%'
              }
            }else{
              value.dj = 'lv1'
              value.jd = '20%'
            }
            
            return <Task key = {index}
            data = {value}
            clickHeadImg={()=>this.onClickHeadImg(value.uid)}
            clickTaskInfo={()=>this.onClickTaskInfo(value.tid)}
            ></Task>
          })
        }
      </WholeStyled>
    );
  }
  onClickHeadImg(tag){
    console.log(tag)
    this.props.history.push({pathname:"/myChildRouter/personalcenter/" + tag});

  }
  onClickTaskInfo(tag){
    console.log(this.props)
    // console.log(tag)
    this.props.history.push({pathname:"/hallChildRouter/taskInfo/" + tag});
    // this.props.history.push('/taskInfo',{tag})
  }
}

export default connect(HighTask);